﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.NeighborUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.event.*;
    import org.aswing.border.*;
    import Display.aswingui.*;

    public class MutualFriendInviteDialogView extends GenericDialogView {

        public static const NUM_PORTRAITS:int = 4;

        private var m_picHasLoaded:Boolean = false;
        private var m_friend:Player;
        private var m_pic:Loader;
        private var m_friendFrameAP:AssetPane;
        private var m_samAsset:DisplayObject;
        private var m_hRuleAsset:DisplayObject;
        private var m_portraits:Array;
        private var m_loaders:Array;
        private var m_portraitsPane:JPanel;

        public function MutualFriendInviteDialogView(_arg1:Dictionary){
            super(_arg1);
        }
        override protected function init():void{
            var _local1:Loader;
            var _local2:String;
            m_acceptTextName = ZLoc.t("Dialogs", "MFI_button");
            m_cancelTextName = "";
            this.m_friend = m_assetDict["friend"];
            this.m_portraits = m_assetDict["portraits"];
            this.m_loaders = new Array();
            if (((this.m_portraits) && (this.m_portraits.length))){
                for each (_local2 in this.m_portraits) {
                    _local1 = LoadingManager.load(_local2, this.fillFriendFrame, LoadingManager.PRIORITY_LOW);
                    _local1.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onLoadPicFail, false, 2);
                };
            };
            this.m_hRuleAsset = (new (m_assetDict["hrule"])() as DisplayObject);
            m_bgAsset = (new (m_assetDict["dialogBG"])() as DisplayObject);
            this.m_samAsset = (new (m_assetDict["sam"])() as DisplayObject);
            this.createTitlePanel();
            this.makeBackground();
            makeCenterPanel();
            ASwingHelper.prepare(this);
        }
        private function fillFriendFrame(_arg1:Event):void{
            var _local2:Sprite = new Sprite();
            var _local3:DisplayObject = _arg1.currentTarget.content;
            _local2.addChild(_local3);
            var _local4:AssetPane = new AssetPane();
            _local4.setAsset(_local2);
            this.m_portraitsPane.appendAll(_local4, ASwingHelper.horizontalStrut(5));
            this.m_picHasLoaded = true;
            ASwingHelper.prepare(this);
        }
        override protected function createTitlePanel():JPanel{
            var _local2:String;
            var _local3:TextFormat;
            super.m_titleFontSize = 17;
            super.m_titleSmallCapsFontSize = 25;
            super.m_titleString = ZLoc.t("Dialogs", "MFI_title");
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            m_titleFontSize = TextFieldUtil.getLocaleFontSize(m_titleSmallCapsFontSize, m_titleFontSize, null);
            if (m_titleString != ""){
                _local2 = m_titleString;
                title = ASwingHelper.makeTextField(_local2, EmbeddedArt.TITLE_FONT, m_titleFontSize, EmbeddedArt.titleColor, 3);
                title.filters = EmbeddedArt.newtitleFilters;
                _local3 = new TextFormat();
                _local3.size = m_titleSmallCapsFontSize;
                TextFieldUtil.formatSmallCaps(title.getTextField(), _local3);
                _local1.append(title);
                title.getTextField().height = (m_titleFontSize * 1.5);
            } else {
                _local1.append(ASwingHelper.verticalStrut(10));
            };
            ASwingHelper.setEasyBorder(_local1, 20);
            return (_local1);
        }
        private function onLoadPicFail(_arg1:Event):void{
            if (!this.m_picHasLoaded){
                _arg1.stopPropagation();
                _arg1.stopImmediatePropagation();
                LoadingManager.cancelLoad(this.m_pic);
                this.m_picHasLoaded = true;
            };
        }
        override protected function makeBackground():void{
            var _local1:MarginBackground = new MarginBackground(m_bgAsset, new Insets(10, 0, 7, 0));
            this.setBackgroundDecorator(_local1);
            this.setPreferredWidth(m_bgAsset.width);
            this.setMinimumWidth(m_bgAsset.width);
            this.setMaximumWidth(m_bgAsset.width);
            this.setLayout(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.CENTER));
        }
        override protected function createHeaderPanel():JPanel{
            var _local1:JPanel = new JPanel(new BorderLayout());
            var _local2:JPanel = this.createCloseButtonPanel();
            var _local3:JPanel = this.createTitlePanel();
            ASwingHelper.prepare(_local2);
            _local1.append(ASwingHelper.horizontalStrut(_local2.getWidth()), BorderLayout.WEST);
            _local1.append(_local3, BorderLayout.CENTER);
            _local1.append(_local2, BorderLayout.EAST);
            return (_local1);
        }
        override protected function createCloseButtonPanel():JPanel{
            var _local1:JPanel = new JPanel(ASwingHelper.softBoxLayoutVertical);
            var _local2:JButton = ASwingHelper.makeMarketCloseButton();
            _local2.addEventListener(MouseEvent.CLICK, this.onCancel, false, 0, true);
            _local1.append(_local2);
            ASwingHelper.setEasyBorder(_local2, 14, 0, 0, 4);
            return (_local1);
        }
        override protected function createTextArea():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            _local1.setPreferredHeight((this.m_samAsset.height + 15));
            _local1.setMinimumHeight((this.m_samAsset.height + 15));
            _local1.setMaximumHeight((this.m_samAsset.height + 15));
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            var _local3:AssetPane = new AssetPane(this.m_samAsset);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local5:String = ZLoc.t("Dialogs", "MFI_message", {name:ZLoc.tn(this.m_friend.snUser.firstName)});
            this.m_portraitsPane = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local6:AssetPane = ASwingHelper.makeMultilineText(_local5, 270, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 18, 3841479, null, true);
            var _local7:AssetPane = new AssetPane(this.m_hRuleAsset);
            _local4.appendAll(ASwingHelper.verticalStrut(10), this.m_portraitsPane, ASwingHelper.verticalStrut(9), _local7, ASwingHelper.verticalStrut(9), _local6);
            _local2.append(ASwingHelper.horizontalStrut(9));
            _local2.append(_local3);
            _local2.append(ASwingHelper.horizontalStrut(9));
            _local2.append(_local4);
            _local1.append(ASwingHelper.verticalStrut(15));
            _local1.append(_local2);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        override protected function createInteriorHolder():JPanel{
            var _local3:JPanel;
            var _local1:JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, -10, AsWingConstants.CENTER));
            var _local2:JPanel = this.createHeaderPanel();
            ASwingHelper.prepare(_local2);
            textArea = this.createTextArea();
            ASwingHelper.prepare(textArea);
            _local1.setBorder(new EmptyBorder(null, new Insets(0, 0, 0, 0)));
            if (m_type != TYPE_NOBUTTONS){
                _local1.append(_local2);
            };
            _local1.append(ASwingHelper.verticalStrut(20));
            _local1.append(textArea);
            _local1.append(ASwingHelper.verticalStrut(BUTTON_MARGIN));
            if (((!((m_type == TYPE_MODAL))) && (!((m_type == TYPE_NOBUTTONS))))){
                _local3 = createButtonPanel();
                _local1.appendAll(ASwingHelper.verticalStrut(-10), _local3);
            };
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        override protected function onAccept(_arg1:AWEvent):void{
            super.onAccept(_arg1);
            FrameManager.navigateTo(("invite.php?mutual=true&ref=mutual_friend_invite&fId=" + this.m_friend.uid));
            Global.player.setShowMFIByID(this.m_friend.uid, false);
        }
        override protected function onCancel(_arg1):void{
            var _local2:String;
            super.onCancel(_arg1);
            for (_local2 in Global.player.MFIDict) {
                Global.player.setShowMFIByID(_local2, false);
            };
        }

    }
}//package Display.NeighborUI 
